#'
#' @TODO 绘制PCA
#' @examples: 
#' @author: *WYK*
#'
common_g = read.delim(file.path(run_home,"7/3.rf_lasso_intersect/common_g.tsv"))[[1]]

library(factoextra)
library(FactoMineR)

data4pca <- train_dat[[1]][common_g, ] %>%
    t() %>%
    as.data.frame() %>%
    rownames_to_column("sample") %>% 
    inner_join(train_dat[[2]])

gr <- data4pca[[ncol(data4pca)]] %>% factor()

pca_res = PCA(data4pca[,-c(1,ncol(data4pca))], scale.unit = TRUE, ncp = 2, graph = F)

p1 <- fviz_pca_ind(X = pca_res, ## pca对象
  axes = 1:2, ## 展示的两个主成分
  geom = 'point', ## 展示individual的形式
  habillage = gr, #分组 factor
  legend.title = 'Groups', ## 分组变量的title
  palette = 'lancet', ## 颜色面板
  addEllipses = F,  ## 是否绘制椭圆
  ellipse.level = 0.95, ## 椭圆的大小
  title = 'PCA', ## 标题
  mean.point = T ## 不删除每个组的重心
  )+
  theme(plot.title = element_text(hjust = 0.5,size=10))

plotout(p = p1,name = 'pca',od = file.path(run_home,'9',"4."),w = 4,h = 4)
